<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<title>修改收获地址信息</title>
</head>
<body>
<fieldset class="layui-elem-field" style="margin:30px;padding:30px">
	<legend>添加用户</legend>
	<div class="layui-field-box">
			<form class="layui-form-pane layui-form" lay-filter="formA">
				<div class="layui-form-item">
					<label class="layui-form-label">用户账号</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="userCode" type="text" placeholder="请输入用户账号"
						required lay-verify="required" autocomplete="off" readonly>
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">收件人名称</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="name" type="text" placeholder="请输入收件人名称"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">收件人电话</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="tel" type="text" placeholder="请输入收件人电话"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
				<label class="layui-form-label">省：</label>
					<div class="layui-input-inline">
						<select name="addr1" lay-verify="required" lay-search lay-filter="addr1"></select>
					</div>
				</div>
				
				<div class="layui-form-item">
				<label class="layui-form-label">市：</label>
					<div class="layui-input-inline">
						<select name="addr2" lay-verify="required" lay-search lay-filter="addr2"></select>
					</div>
				</div>
				
				<div class="layui-form-item">
				<label class="layui-form-label">区：</label>
					<div class="layui-input-inline">
						<select name="addr3" lay-verify="required" lay-search></select>
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">详细地址</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="addr4" type="text" placeholder="请输入详细地址"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>		
				
				<div class="layui-form-item">
					<div class="layui-input-inline">
						<input type="button" value="确定" class="layui-btn" lay-submit lay-filter="updAddr"  />
						<input type="reset" value="重置" class="layui-btn layui-btn-primary" />
					</div>
				</div>
				
				<input type="hidden" name='code'/>
			</form>
		</div>
		
	</fieldset>
</body>
<script type="text/javascript">
	getSelect('addr1','000000',init)
	function getSelect(selectid,parentCode,func){
		if(parentCode==''){
			$("select[name^='addr']").empty();
			form.render("select");
			return; 
		}
		ajax({parentCode:parentCode},'/addrtol/updget.do','json',function(data){
			var html = "<option value=''>-- 请选择 --</option>";
			$.each(data,function(i,dom){
				html += "<option value='"+dom.code+"'>"+dom.name+"</option>"
			});
			$("select[name='"+selectid+"']").html(html);
			form.render("select");
			func();
		})
	}

	formsele('addr1','addr2');
	formsele('addr2','addr3');
	function formsele(filter,selectid){
		form.on("select(" + filter + ")",function(data){
			getSelect(selectid,data.value);
		})
	}
	
	function init(){	
		var userCode = '<%=request.getParameter("userCode") %>'
			ajax({userCode:userCode},'/address/get.do','json',function(data){
// 				$("input[name='userCode']").val(data.userCode);
// 				$("input[name='code']").val(data.code);
// 				$("input[name='name']").val(data.name);
// 				$("input[name='tel']").val(data.tel);
// 				$("input[name='addr4']").val(data.addr4);
				
// 				$("select[name='addr1'] option[value='"+data.addr1+"']").prop('selected','selected');
				form.val("formA",data)
				getSelect('addr2',data.addr1,function(){
					$("select[name='addr2']>option[value='"+data.addr2+"']").prop('selected','selected');
					form.render('select');
				})
				getSelect('addr3',data.addr2,function(){
					$("select[name='addr3']>option[value='"+data.addr3+"']").prop('selected','selected');
					form.render('select');
				})
			})
	}
	
	formOn('submit(updAddr)','/address/updAddr.do','text',function(data){
		if(1==data){
			layer.msg("修改成功",toClose)
		}else{
			layer.msg("修改失败")
		}
	})
</script>
</html>